package com.edu.Filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class EncoderFilter implements Filter {

    private String encoding;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        encoding = filterConfig.getInitParameter("encoding");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req= (HttpServletRequest) servletRequest;
        //处理整个项目所有的Servlet请求乱码
        req.setCharacterEncoding(encoding);
        //放行
        filterChain.doFilter(req, servletResponse);
    }

    @Override
    public void destroy() {

    }
}
